package com.zhang.file.service.impl;

import com.zhang.common.oss.minio.MinioUtil;
import com.zhang.file.service.IFileAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.List;

@Service
public class MinioFileActionImpl implements IFileAction {
    @Autowired
    private MinioUtil minioUtil;

    @Override
    public InputStream readFile(String bucket, String filePath) throws Exception {
        return minioUtil.download(bucket, filePath);
    }

    @Override
    public List<String> listBuckets() {
        try {
            return minioUtil.listBuckets();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void uploadFile(InputStream inputStream, String bucket, String objectName) {
        try {
            minioUtil.uploadFile(inputStream, bucket, objectName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    public void deleteFile(String bucket, String filePath) {
        try {
            minioUtil.deleteObject(bucket, filePath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
